package org.bozo.im.service.core.roster;

import java.util.ArrayList;

import org.bozo.im.common.types.Protocol;
import org.bozo.im.common.types.RawContact;
import org.bozo.im.service.core.database.DatabaseHelper;

import android.content.Context;

public class IMRoster {

	private AbstractContactProvider mContactProvider;
	private ArrayList<ContactDesc> mDescs;

	public IMRoster(Context pService, DatabaseHelper pDatabase) {
		mContactProvider = AbstractContactProvider.getProvider(pService, pDatabase);
	}

	public ArrayList<RawContact> getContactsList() {
		return mContactProvider.getContacts();
	}

	public void addContact(Protocol pProtocol, String pHandle, String pDisplayName) {
		if (mDescs == null)
			mDescs = new ArrayList<ContactDesc>();
		mDescs.add(ContactDesc.build(pProtocol, pHandle, pDisplayName));
	}
	
	public void pushContacts() {
		mContactProvider.addContacts(mDescs);
		mDescs = null;
	}

	public RawContact getContact(Protocol pProtocol, String pHandle) {
		return mContactProvider.getContact(pProtocol, pHandle);
	}

	public void itemModified(RawContact pRawContact, RawContact.Field pField) {
		mContactProvider.updateContact(pRawContact, pField);
	}
}
